const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
  const AdminRole = sequelize.define('AdminRole', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  adminId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'admin_id',
    references: {
      model: 'Admins',
      key: 'id'
    },
    comment: '管理员ID'
  },
  roleId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'role_id',
    references: {
      model: 'Roles',
      key: 'id'
    },
    comment: '角色ID'
  },
  assignedBy: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'assigned_by',
    references: {
      model: 'Admins',
      key: 'id'
    },
    comment: '分配者ID'
  },
  assignedAt: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW,
    field: 'assigned_at',
    comment: '分配时间'
  }
}, {
  tableName: 'admin_roles',
  timestamps: false,
  indexes: [
    {
      unique: true,
      fields: ['admin_id', 'role_id']
    }
  ]
});

  return AdminRole;
};